package com.octo.poker.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.octo.poker.PokerGame;
import com.octo.poker.data.Hand;
import com.octo.poker.repository.GameRepository;
import com.octo.poker.vue.PokerGameForm;

@Controller

@RequestMapping("/poker.html")
public class PokerGameController {

	@Autowired
	protected PokerGame pg;
		
	@RequestMapping(method = RequestMethod.GET)
	public void afficher(Model model){
		//GameRepository gameRepository = new GameRepository();
		model.addAttribute("pokerGameForm",new PokerGameForm());
		//model.addAttribute("pokerGame",new PokerGame());
		//model.addAttribute("listGames", gameRepository.getLastFiveGames());
	}
	
	@RequestMapping(method = RequestMethod.POST)
	public void comparer(PokerGameForm form,BindingResult result, Model model){
		String yours = form.getYours();
		String his = form.getHis();
		Hand hYours = new Hand(yours);
		Hand hHis = new Hand(his);
		//PokerGame pg = (PokerGame) model.asMap().get("pokerGame");
		String myResult = pg.gameResult(hYours, hHis);
		model.addAttribute("myResult",myResult);
	}

	public PokerGame getPg() {
		return pg;
	}

	public void setPg(PokerGame pg) {
		this.pg = pg;
	}
	
	
	
	
	
}
